<?php

namespace app\admin\controller;

class Message extends Common
{
    public function index()
    {
        if (request()->isPost()) {
            $key = input('post.key');
            $page = input('page') ? input('page') : 1;
            $pageSize = input('limit') ? input('limit') : config('pageSize');
            $list = db('message')
                ->where('name|mobile|content', 'like', "%" . $key . "%")
                ->order('create_time desc')
                ->paginate(['list_rows' => $pageSize, 'page' => $page])
                ->toArray();
            foreach ($list['data'] as $k => $v) {
                $list['data'][$k]['create_time'] = date('Y-m-d H:s', $v['create_time']);
            }
            return ['code' => 0, 'msg' => '获取成功!', 'data' => $list['data'], 'count' => $list['total']];
        }
        return $this->fetch();
    }
    //删除留言
    public function del()
    {
        $map['id'] = input('id');
        db('message')->where($map)->delete();
        return ['code' => 1, 'msg' => '删除成功!'];
    }
    public function delall()
    {
        $map[] = ['id', 'IN', input('param.ids/a')];
        db('message')->where($map)->delete();
        $result['msg'] = '删除成功！';
        $result['code'] = 1;
        $result['url'] = url('index');
        return $result;
    }
}